<?php // BMI Calculator
$popular_food_name = "BMI Calculator";
$popular_food_description = "Calculates BMI";
//This functoion calculates BMI of people
// BMI = ( Weight in Pounds / ( Height in inches ) x ( Height in inches ) ) x 703
function BMI_Calculate($weight, $height_feet, $height_inches) {
	
//get the converted height
$converted_height = ($height_feet * 12) + $height_inches;
//Calculate the BMI
$BMI = $weight * 703 / ($converted_height * $converted_height);
return number_format($BMI, 1);
} // End of BMI_Calculate Function

?>
<?php
include('header.php');
?>
<link rel="stylesheet" type="text/css" href="../css/BMI.css" />

<div class="container">
	<section id="content">
<form action="BMICalculator.php" method="post">

<div id="bmi_title">Body Mass Index Calculator</div>
<div id="bmi_description"><br>Body Mass Index (BMI) is a measure of a person's weight in relation to height, not body composition.<br>
BMI values apply to both men and women, regardless of age or frame size. Use this information, along with other health indices, to assess your need to adjust your weight.
<br>
<br>
</div>

<div><h5>
Height (Feet):
<select name="height_feet">

<option value="">Select..</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>

</select>
</h5>
</div>

<div>
<h5>
Height (Inches):
<select name="height_inches" id="height_inches" >

<option value="">Select..</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>

</select>
</h5>
</div>

<div>
<h5>
Weight (Pounds):
<input name="weight" type="text" size="5" maxlength="3" />
</h5>
</div>

<p Align = "Center">
<div>
<input type="submit" name="submit" value="Calculate!" />
</div>
</p>
</form>

<?Php
// Check for form submission:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	// Minimal form validation:
	if (isset($_POST['weight'], $_POST['height_feet'], $_POST['height_inches']) &&
	 is_numeric($_POST['weight']) && is_numeric($_POST['height_feet']) && is_numeric($_POST['height_inches']) ) {
	
		// Calculate the results:
		$BMI = BMI_Calculate($_POST['weight'], $_POST['height_feet'], $_POST['height_inches']);
		
		// Print the results:
		echo '<div id="result"><h1>BMI Result</h1>
		 <p>Your height is ' . $_POST['height_feet'] . ' feet and ' . $_POST['height_inches'] . ' inches <br />
			Your Weight is ' . $_POST['weight'] . ' <br /> 
			Your BMI is ' . $BMI . '.  </p>
			What your result means:';
			if ($BMI <= 18.5) {
				echo '<p>You are Underweight.</p>';
			}
			else if (($BMI > 18.5) && ($BMI <= 24.9)) {
				echo '<p>You are Normal weight.</p>';
			}
			else if (($BMI > 24.9) && ($BMI <= 29.9)) {
				echo '<p>You are Over weight.</p>';
			}
			else if (($BMI > 29.9) && ($BMI <= 39.9)) {
				echo '<p>You are Obese.</p>';
			}
			else {
				echo '<p>You are Morbidly Obese.</p></div>';
			}

	}
	 
	else { // Invalid submitted values.
		echo '
		<p id="errormsg">Please enter a valid height and weight to determine your BMI.</p>';
	}

}
?>

</section><!-- content -->

</div><!-- container -->

<?php
include('footer.php');
?>
